﻿// COMMON
function ChangeDrugMainType(DrugMainTypeID) {
    var mes = Portal.SODC.IDIS.PenonlineUpdate.ServerSideGetSubDrugType(DrugMainTypeID).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes);
        return;
    }
    $("#_legalDrugPermitSubType").html(mes);
}
function AppendDrugPermitItem() {
    if ($("#_legalDrugPermitSubType").val() == "0") {
        alert('Bạn chưa lựa chọn loại ma túy');
        return;
    }
    var mes = Portal.SODC.IDIS.PenonlineUpdate.ServerSideGetTableForDrugTypeItems($("#_legalDrugPermitSubType option:selected").text(), $("#_legalDrugPermitSubType").val(), $("#_drugLegalKG").val(), $("#_drugLegalL").val(), $("#_drugLegalPercent").val(), $("#_drugTypeItemTemp").html()).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes);
        return;
    }
    $("#_drugLegalInfomation").html(mes);
}
function DeleteTempTableItemUpdateFrm(ItemID) {
    var mes = Portal.SODC.IDIS.PenonlineUpdate.ServerSideDeleteItemTempTable(ItemID).value;
    $("#_drugLegalInfomation").html(mes);
}
function ClientDelete(permitid) {
    var mes = Portal.SODC.IDIS.PenonlineMgr.ServerSideDelete(permitid).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes);
        return;
    }
    alert(mes);
    $("#resultcontent").html('');
}
// SEARCH & EXPORT
function ClientSearch() {
    DateRecordedFrom = document.getElementById("drpDayDateRecordedFrom").options[document.getElementById("drpDayDateRecordedFrom").selectedIndex].value + '/' + document.getElementById("drpMonthDateRecordedFrom").options[document.getElementById("drpMonthDateRecordedFrom").selectedIndex].value + '/' + document.getElementById("drpYearDateRecordedFrom").options[document.getElementById("drpYearDateRecordedFrom").selectedIndex].value;
    DateRecordedTo = document.getElementById("drpDayDateRecordedTo").options[document.getElementById("drpDayDateRecordedTo").selectedIndex].value + '/' + document.getElementById("drpMonthDateRecordedTo").options[document.getElementById("drpMonthDateRecordedTo").selectedIndex].value + '/' + document.getElementById("drpYearDateRecordedTo").options[document.getElementById("drpYearDateRecordedTo").selectedIndex].value;

    var mes = Portal.SODC.IDIS.PenonlineMgr.ServerSideSearchTermByPermits(DateRecordedFrom, DateRecordedTo).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes);
        return;
    }
    $("#resultcontent").html(mes);
}
function ClientSideExportData() {
    DateRecordedFrom = document.getElementById("drpDayDateRecordedFrom").options[document.getElementById("drpDayDateRecordedFrom").selectedIndex].value + '/' + document.getElementById("drpMonthDateRecordedFrom").options[document.getElementById("drpMonthDateRecordedFrom").selectedIndex].value + '/' + document.getElementById("drpYearDateRecordedFrom").options[document.getElementById("drpYearDateRecordedFrom").selectedIndex].value;
    DateRecordedTo = document.getElementById("drpDayDateRecordedTo").options[document.getElementById("drpDayDateRecordedTo").selectedIndex].value + '/' + document.getElementById("drpMonthDateRecordedTo").options[document.getElementById("drpMonthDateRecordedTo").selectedIndex].value + '/' + document.getElementById("drpYearDateRecordedTo").options[document.getElementById("drpYearDateRecordedTo").selectedIndex].value;

    var mes = Portal.SODC.IDIS.PenonlineMgr.ServerExportData(DateRecordedFrom, DateRecordedTo).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", "").trim());
        return;
    }
    else {
        window.open(mes, '_blank');
    }

}
// INSERT
function ClientInsertPenonlineItem() {
    if ($("#PenonlineNumber").val().trim() == "") { alert('Số ra thông báo PENONLINE không có dữ liệu!'); $("#PenonlineNumber").focus(); return; }
    PenonlineDate = document.getElementById("drpDayPenonlineDate").options[document.getElementById("drpDayPenonlineDate").selectedIndex].value + '/' + document.getElementById("drpMonthPenonlineDate").options[document.getElementById("drpMonthPenonlineDate").selectedIndex].value + '/' + document.getElementById("drpYearPenonlineDate").options[document.getElementById("drpYearPenonlineDate").selectedIndex].value;
    //if ($("#PenonlineDate").val().trim() == "") { alert('Ngày ra thông báo PENONLINE không có dữ liệu!'); $("#PenonlineDate").focus(); return; }
    if ($("#PenonlineGate").val().trim() == "") { alert('Cửa khẩu dự kiến không có dữ liệu!'); $("#PenonlineGate").focus(); return; }

    //alert($('input[name=PenonlineConfirm]:checked').val());

    var mes = Portal.SODC.IDIS.PenonlineUpdate.ServerSideInsert($("#PenonlineNumber").val(), PenonlineDate, $("#PenonlineCountry").val(), $("#PenonlineGate").val(), $("#_legalDrugPermitOfMinistry").val(), $("#ExportUnitType").val(), $("#ImportUnitType").val(), $("#MadeByUnitType").val(), $('input[name=PenonlineConfirm]:checked').val()).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes);
        return;
    }
    alert(mes);
}
function ClientUpdatePenonlineItem() {
    if ($("#PenonlineNumber").val().trim() == "") { alert('Số ra thông báo PENONLINE không có dữ liệu!'); $("#PenonlineNumber").focus(); return; }
    //if ($("#PenonlineDate").val().trim() == "") { alert('Ngày ra thông báo PENONLINE không có dữ liệu!'); $("#PenonlineDate").focus(); return; }
    PenonlineDate = document.getElementById("drpDayPenonlineDate").options[document.getElementById("drpDayPenonlineDate").selectedIndex].value + '/' + document.getElementById("drpMonthPenonlineDate").options[document.getElementById("drpMonthPenonlineDate").selectedIndex].value + '/' + document.getElementById("drpYearPenonlineDate").options[document.getElementById("drpYearPenonlineDate").selectedIndex].value;
    if ($("#PenonlineGate").val().trim() == "") { alert('Cửa khẩu dự kiến không có dữ liệu!'); $("#PenonlineGate").focus(); return; }

    var mes = Portal.SODC.IDIS.PenonlineUpdate.ServerSideUpdate($("#updatepermitid").val(), $("#PenonlineNumber").val(), PenonlineDate, $("#PenonlineCountry").val(), $("#PenonlineGate").val(), $("#_legalDrugPermitOfMinistry").val(), $("#ExportUnitType").val(), $("#ImportUnitType").val(), $("#MadeByUnitType").val(), $('input[name=PenonlineConfirm]:checked').val()).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes);
        return;
    }
    alert(mes);
}